package cn.edu.zafu.bigdata.lwg;

public class ArrayElementExample {

    public static void main(String[] args) {
        int[] arr = {10, 20, 30, 40, 50};
        int index = 5;

        try {
            int element = getElement(arr, index);
            System.out.println("元素是: " + element);
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("错误：索引超出数组范围。");
        }
    }
    public static int getElement(int[] arr, int index) {
        if (index < 0 || index >= arr.length) {
            throw new ArrayIndexOutOfBoundsException("索引超出数组范围");
        } else {
            return arr[index];
        }
    }
}
